﻿using System;
using Portal.Data.Entity;
using Portal.Data.Helper;
using Portal.Core.Utils;

namespace Ajax.UserControl
{
    public partial class Ajax_UserControl_Banner : System.Web.UI.UserControl
    {
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            dynamic data = new DynamicJsonObject();
            data.done = false;
            var action = Request["act"];
            switch (action)
            {
                case "clicked":
                    int id;
                    int.TryParse(Request["id"], out id);
                    if (id > 0 && Session["banner@click@" + id] == null)
                    {
                        var banner = Banner.FindByPrimaryKey(id);
                        if (banner != null)
                        {
                            banner.Clicked++;
                            ORMHelper.InstanceIgnorePermission.Save(banner);
                            data.done = true;
                            Session["banner@click@" + id] = id;
                        }
                    }
                    break;
            }

            writer.Write(data);
        }
    }
}